import { createApp } from 'vue'
import 'normalize.css/normalize.css'
import ElementPlus from 'element-plus'
import 'element-plus/theme-chalk/index.css'
import 'element-plus/dist/index.css';
import '@/styles/index.scss'
import '@/styles/reset.scss'
import App from './App.vue'
// 文件上传组件
import FileUpload from "@/components/FileUpload"
// 图片上传组件
import ImageUpload from "@/components/ImageUpload"
import directive from './directive' // directive
import Pagination from "@/components/Pagination/index.vue"; 
// 图片上传组件
//import ImageUpload from "@/components/ImageUpload/index.vue"
import service from '@/utils/request'
import VueAxios from 'vue-axios'
import router from './router'
import store from './store'
import './router/guard'
import { createI18n } from 'vue-i18n'
import { messages, zh_cn, en } from '@/lang'
import SvgIcon from '@/components/SvgIcon/index.vue'
import ECharts from 'vue-echarts'
import { use } from "echarts/core"
import { CanvasRenderer } from 'echarts/renderers'
import 'virtual:svg-icons-register';
import locale from "element-plus/es/locale/lang/zh-cn"
import HelpHint from '@/components/Hint/helpHint.vue'
import { useDict } from '@/utils/dict' 
import { dragTable } from '@/utils/common'
import { downloadFile } from "@/utils/downloadFile";
import SearchReset from '@/components/SearchReset/index.vue'
import FileUploadStep from "@/components/FileUploadStep/index.vue"
import RightToolbar from "@/components/RightToolbar"
import './permission'
// 字典标签组件
import DictTag from '@/components/DictTag/index.vue'
import {
  BarChart, LineChart, PieChart,
  ScatterChart, EffectScatterChart,
  MapChart, RadarChart, GaugeChart,
} from 'echarts/charts'
import {
  GridComponent, TooltipComponent, PolarComponent,
  GeoComponent, LegendComponent, TitleComponent,
  VisualMapComponent, DatasetComponent, ToolboxComponent
} from 'echarts/components'
use([
  CanvasRenderer,
  BarChart, LineChart, PieChart, MapChart, GaugeChart,
  RadarChart, ScatterChart, EffectScatterChart,
  GridComponent, TooltipComponent, PolarComponent,
  GeoComponent, LegendComponent, TitleComponent,
  VisualMapComponent, DatasetComponent, ToolboxComponent
])
import plugins from './plugins'

import print from 'vue3-print-nb'
import * as ElementPlusIconsVue from '@element-plus/icons-vue' 
import { parseTime, resetForm, addDateRange, handleTree, selectDictLabel, selectDictLabels } from '@/utils/ruoyi'

const app = createApp(App)
  .use(print)
  .use(store)
  .use(router) 
  .use(plugins)
  .use(VueAxios, service)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.config.globalProperties.useDict = useDict 
app.config.globalProperties.parseTime = parseTime
app.config.globalProperties.resetForm = resetForm   
app.config.globalProperties.dragTable = dragTable
app.config.globalProperties.addDateRange = addDateRange
app.config.globalProperties.handleTree = handleTree
app.config.globalProperties.selectDictLabel = selectDictLabel
app.config.globalProperties.selectDictLabels = selectDictLabels
app.config.globalProperties.downloadFile = downloadFile
//echarts
// 全局组件挂载
app.component('DictTag', DictTag)
app.component('v-chart', ECharts)
app.component('Pagination', Pagination)
app.component('HelpHint', HelpHint) 
app.component('FileUpload', FileUpload)
app.component('FileUploadStep', FileUploadStep)
app.component('ImageUpload', ImageUpload)
app.component('SearchReset', SearchReset)
app.component('RightToolbar', RightToolbar)
//i18n
const i18n = createI18n({
  legacy: false,
  locale: en,
  fallbackLocale: en,
  messages,
})
app.use(i18n)

//element-plus
app.use(ElementPlus, {
  locale
})



//axios
app.config.globalProperties.$axios = service

// register globally
app.component('svg-icon', SvgIcon)
directive(app)
//svg-icon
// const requireAll = requireContext => requireContext.keys().map(requireContext)
// const req = require.context('@/icons/svg', false, /\.svg$/)
// requireAll(req)

// const reqsales = require.context('@/icons/sales', false, /\.svg$/)
// requireAll(reqsales)

app.mount('#app')